a=int(input("ВВедите четырехзначное число:"))
if 1000<=a and a<10000:
    s = str(a // 1000)
    q = str(a // 100 % 10)
    c = str(a // 10 % 10)
    e = str(a % 10)

    x1 = int(s)
    x2 = int(q)
    x3 = int(c)
    x4 = int(e)
    x5 = int(s+q)
    x6 = int(q+c)
    x7 = int(c+e)
    x8 = int(s+q+c)
    x9 = int(q+c+e)
    x10 = int(s+q+c+e)



    for i in range(2,x1//2+1):
       v = a % i
       if v ==0:
           x1=0
       else:
           i += 1
    for i in range(2,x2//2+1):
       v = a % i
       if v ==0:
           x2=0
       else:
           i += 1
    for i in range(2,x3//2+1):
       v = a % i
       if v ==0:
           x3=0
       else:
           i += 1
    for i in range(2,x4//2+1):
       v = a % i
       if v ==0:
           x4=0
       else:
           i += 1
    for i in range(2,x5//2+1):
       v = a % i
       if v ==0:
           x5=0
       else:
           i += 1
    for i in range(2,x6//2+1):
       v = a % i
       if v ==0:
           x6=0
       else:
           i += 1
    for i in range(2,x7//2+1):
       v = a % i
       if v ==0:
           x7=0
       else:
           i += 1
    for i in range(2,x8//2+1):
       v = a % i
       if v ==0:
           x8=0
       else:
           i += 1
    for i in range(2,x9//2+1):
       v = a % i
       if v ==0:
           x9=0
       else:
           i += 1
    for i in range(2,x10//2+1):
       v = a % i
       if v ==0:
           x10=0
       else:
           i += 1
    print(max(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10))

else:
    print(0)









